#include <iostream>
#include <sstream>
#include <fstream>
#include <string>
#include <cstring>

//#include "rapid/rapidxml.hpp"
//#include "rapid/rapidxml_print.hpp"

#include "ReadConfig.h"

using namespace std;

ReadConfig::ReadConfig(){
	cout << "Constructor" << endl;
}
ReadConfig::~ReadConfig(){
	cout << "Destructor" << endl;
}
void ReadConfig::start(){
	int length;
	char * buffer;

    ifstream is;
	is.open ("example.xml", ios::binary );
	// get length of file:
	is.seekg (0, ios::end);
	length = is.tellg();
	is.seekg (0, ios::beg);

	// allocate memory:
	buffer = new char [length];

	// read data as a block:
	is.read (buffer,length);
	is.close();

	//Parse the original document
	rapidxml::xml_document<> doc;
	doc.parse<0>(buffer);
	// first node is xml tag
	rapidxml::xml_node<char>* backup_tag = doc.first_node();

	//Insert something
	//rapidxml::xml_node<> *node = doc.allocate_node(rapidxml::node_element, "author", "John Doe");
	//doc.first_node()->append_node(node);
	rapidxml::xml_node<char>* location_tag = backup_tag->first_node(); 
	rapidxml::xml_node<char>* directory_tag = location_tag->first_node(); 
	string directory_dir = directory_tag->value();

	//Location* loc = new Location(location);
	//GETTING ALL PRE COMMANDS!
	//GETTING ALL POST COMMANDS
		//GETTING ALL <command>ping google.com

	cout << "\n\n\n****************** CONFIG Start *******************\n\n\n";
	cout << "Location directory #1 " << directory_dir << "\n";
	cout << "\n\n****************** CONFIG END *******************\n\n\n";
	//delete loc;
}	
